#region Copyright RenGuiYou. All rights reserved.
//=====================================================
// NeatlyFrameWork
// Author:      RenGuiyou
// Feedback: 	mailto:750539605@qq.com
//=====================================================
#endregion

using System;
using UnityEngine;
using UnityEngine.Serialization;

namespace Neatly.UI
{
    [Serializable]
    public class NFontData : ISerializationCallbackReceiver
    {
        [SerializeField]
        [FormerlySerializedAs("font")]
        private Font m_Font;

        [SerializeField]
        [FormerlySerializedAs("fontSize")]
        private int m_FontSize;

        [SerializeField]
        [FormerlySerializedAs("fontStyle")]
        private FontStyle m_FontStyle;

        [SerializeField]
        private bool m_BestFit;

        [SerializeField]
        private int m_MinSize;

        [SerializeField]
        private int m_MaxSize;

        [SerializeField]
        [FormerlySerializedAs("alignment")]
        private TextAnchor m_Alignment;

        [SerializeField]
        private bool m_AlignByGeometry;

        [SerializeField]
        private HorizontalWrapMode m_HorizontalOverflow;

        [SerializeField]
        private VerticalWrapMode m_VerticalOverflow;

        [SerializeField]
        private float m_LineSpacing;

        public static NFontData defaultFontData
        {
            get
            {
                var fontData = new NFontData
                {
                    m_FontSize = 20,
                    m_LineSpacing = 1f,
                    m_FontStyle = FontStyle.Normal,
                    m_BestFit = false,
                    m_MinSize = 20,
                    m_MaxSize = 20,
                    m_Alignment = TextAnchor.UpperLeft,
                    m_HorizontalOverflow = HorizontalWrapMode.Wrap,
                    m_VerticalOverflow = VerticalWrapMode.Truncate,
                    m_AlignByGeometry = false
                };
                return fontData;
            }
        }

        public Font font
        {
            get => m_Font;
            set => m_Font = value;
        }

        public int fontSize
        {
            get => m_FontSize;
            set => m_FontSize = value;
        }

        public FontStyle fontStyle
        {
            get => m_FontStyle;
            set => m_FontStyle = value;
        }

        public bool bestFit
        {
            get => m_BestFit;
            set => m_BestFit = value;
        }

        public int minSize
        {
            get => m_MinSize;
            set => m_MinSize = value;
        }

        public int maxSize
        {
            get => m_MaxSize;
            set => m_MaxSize = value;
        }

        public TextAnchor alignment
        {
            get => m_Alignment;
            set => m_Alignment = value;
        }

        public bool alignByGeometry
        {
            get => m_AlignByGeometry;
            set => m_AlignByGeometry = value;
        }

        public HorizontalWrapMode horizontalOverflow
        {
            get => m_HorizontalOverflow;
            set => m_HorizontalOverflow = value;
        }

        public VerticalWrapMode verticalOverflow
        {
            get => m_VerticalOverflow;
            set => m_VerticalOverflow = value;
        }

        public float lineSpacing
        {
            get => m_LineSpacing;
            set => m_LineSpacing = value;
        }

        void ISerializationCallbackReceiver.OnBeforeSerialize()
        { }

        void ISerializationCallbackReceiver.OnAfterDeserialize()
        {
            m_FontSize = Mathf.Clamp(m_FontSize, 0, 300);
            m_MinSize = Mathf.Clamp(m_MinSize, 0, m_FontSize);
            m_MaxSize = Mathf.Clamp(m_MaxSize, m_FontSize, 300);
        }
    }
}

